home *** CD-ROM | disk | FTP | other *** search
- /*
- File: TextField.h
-
- Contains: TextEdit class to contain TextEdit from Toolbox
-
-
- Written by: Andrew Taylor
-
- Theory of Operation:
- Quick and dirty wrapper for TextEdit
-
- Modified from Jens Alfke's FacetList
- This is a quick-n-dirty linked list of TextFields. To use it, create a
- TextFieldList and use the Add and Remove methods to add/remove TextFields.
- To iterate over all the TextFields, do something like this:
-
- for ( TextFieldLink *fl = fieldList.First(); fl->GetTextField(); fl = fl->Next() )
- DoSomethingWithTextField( fl->GetTextField() );
-
- Copyright: © 1995 by Appropriate Solutions, Inc., all rights reserved.
-
- Change History (most recent first):
-
-
- <0> started
- */
-
- #ifndef _TEXTFIELD_
- #define _TEXTFIELD_
-
- #include <TextEdit.h>
-
-
- #define chTab 0x09
- #define chEnter 0x03
- #define chReturn 0x0d
-
-
- //========================================================================================
- // TextField
- //========================================================================================
-
- class TextField
- {
- public:
-
- TextField();
- ~TextField();
- void InitTextField(ODTypeToken id, short maxChars, Rect *destRect);
- // id identifies what this field is used for
- // destRect, viewRect are passed to TENew.
- // maxChars is the maximum characters allowed in the field
- void ReleaseTextField();
- // dispose of TextEdit record
-
- ODTypeToken GetID() {return fIdentifier;}
- // returns field identifier
-
- Boolean KeyStroke(char inKey, short modifiers);
- // enter keystroke into TE record
- // returns true if keystroke accepted
- Boolean ContainsPoint(Point where);
- // Determines if point is contained within the view rect.
- void MouseClick(Point where, EventRecord *event);
- // pass mouse click to TextEdit
- void Draw(RgnHandle invalRgn);
- // draw frame, update TextEdit display
-
- Handle GetTextHandle(long *usedLength);
- // returns TextEdit record text handle
- Handle GetSelectedPtr(Ptr *data, long *length);
- // set ptr to selected text. Set length of selected text.
- // caller is expected to lock and unlock handle if use of ptr
- // will cause memory move.
- void SetSelection(long start, long end);
- // set the selection range
- void GetText(Str255 str);
- // retrieve text from TextEdit record
- void SetText(Str255 str);
- // load TextEdit record with text
- Boolean Validate();
- // return true if contents valid, false otherwise
- // should be called when field keyboard focus is being removed
- // displays reason for failure to user.
-
- void Activate();
- // make this the active TE record
- void Deactivate();
- // deactivate TE record
- void Idle();
- // do some idle time.
-
- void Cut();
- void Copy();
- void Paste();
- void Clear();
- Boolean HaveSelection();
-
- protected:
- ODTypeToken fIdentifier;
- TEHandle fTheTE;
- short fMaxChars;
- short fAnchorPoint;
- };
-
-
- //========================================================================================
- // LabeledTextField
- //========================================================================================
-
- class LabeledTextField : public TextField
- {
- public:
-
- LabeledTextField();
- ~LabeledTextField();
- void InitTextField(ODTypeToken id, short maxChars, short lblWidth, Rect *destRect, Str255 label);
- // id identifies what this field is used for
- // label is a string displayed to the left of the field
- // destRect is passed to TENew.
- // maxChars is the maximum characters allowed in the field
- void Draw(RgnHandle invalRgn);
-
- protected:
- Str255 fLabel;
- Rect fRect;
- };
-
-
- //========================================================================================
- // TextFieldLink
- //========================================================================================
-
- class TextFieldLink
- {
- public:
-
- TextField* GetTextField( ) {return fTextField;}
- TextFieldLink* Next( ) {return fNext;}
- TextFieldLink* Previous( ) {return fPrev;}
-
- protected:
- TextFieldLink( TextField*, TextFieldLink *list );
- TextFieldLink( );
- ~TextFieldLink( );
-
- TextField *fTextField;
- TextFieldLink *fPrev,
- *fNext;
-
- friend class TextFieldList;
- };
-
-
- //========================================================================================
- // TextFieldList
- //========================================================================================
-
- class TextFieldList : public TextFieldLink
- {
- public:
- TextFieldList( );
- ~TextFieldList( );
- void Add( TextField* );
- void Add(ODTypeToken id, short maxChars, Rect *destRect);
- void Add(ODTypeToken id, short maxChars, short lblWidth, Rect *destRect, Str255 label);
- void Remove( TextField* );
- void InvalAllTextFields( );
- TextFieldLink* First( ) {return fNext;}
- };
-
-
- #endif